package com.google.code.p.odbcconnectionchecker;

import java.awt.AWTException;
import java.awt.SystemTray;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import com.google.code.p.odbcconnectionchecker.ConnectionCheckerTrayIcon;

public class ConnectionChecker {
	
	public ConnectionChecker () {
		new ConnectionCheckerTrayIcon();
		SystemTray tray = SystemTray.getSystemTray();
		try {
			tray.add(ConnectionCheckerTrayIcon.getTrayIcon());
		} catch (AWTException e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		if (!SystemTray.isSupported()) {
			System.out.println("This application requires System Tray.");
			return;
		}
		new ConnectionChecker();
	}
	
	/**
	 * Application's Jar's folder 
	 * @return A String
	 */
	public static String getJarPath () { 
		String path = ConnectionCheckerTrayIcon.class.getProtectionDomain().getCodeSource().getLocation().getPath();
		String decodedPath = "";
		try {
			decodedPath = URLDecoder.decode(path, "UTF-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		return (decodedPath);
	}
}
